package com.agann.model;

import java.sql.Date;
import java.sql.Time;

public abstract class Record{
	
	/**
	 * Predefined Record Type
	 */
	public static final String MONTH_RECORD = "month";
	public static final String WEEK_RECORD = "week";
	public static final String DAY_RECORD = "day";
	public static final String FOURHOUR_RECORD = "4h";
	public static final String ONEHOUR_RECORD = "1h";
	public static final String HALFHOUR_RECORD = "30m";
	public static final String QUARTERHOUR_RECORD = "15m";
	public static final String FIVEMIN_RECORD = "5m";
	public static final String ONEMIN_RECORD = "1m";
	
	private String type;
	private Date date;
	private Time time;
	private double open;
	private double high;
	private double low;
	private double close;
	private int volumn;
	
	/**
	 * 
	 * @param record
	 */
	public Record(String record, String type) {
		
		this.type = type;
		
		String[] r  = record.split(",");
		this.date   = Date.valueOf(r[0].replace('.', '-'));
		this.time   = Time.valueOf(r[1]+":00");
		this.open   = Double.parseDouble(r[2]);
		this.high   = Double.parseDouble(r[3]);
		this.low    = Double.parseDouble(r[4]);
		this.close  = Double.parseDouble(r[5]);
		this.volumn = Integer.parseInt(r[6]);
	}
	
	

	@Override
	public String toString() {
		return "CRecord [type=" + type + ", date=" + date + ", time=" + time
				+ ", open=" + open + ", high=" + high + ", low=" + low
				+ ", close=" + close + ", volumn=" + volumn + "]";
	}



	public String toCSVRecord() {
		String ret = date.toString().replace('-', '.') + ","
				+ time.toString().substring(0, 5) + "," + open + "," + high
				+ "," + low + "," + close + "," + volumn;
		return ret;
	}



	public String getType() {
		return type;
	}



	public void setType(String type) {
		this.type = type;
	}



	public Date getDate() {
		return date;
	}



	public void setDate(Date date) {
		this.date = date;
	}



	public Time getTime() {
		return time;
	}



	public void setTime(Time time) {
		this.time = time;
	}



	public double getOpen() {
		return open;
	}



	public void setOpen(double open) {
		this.open = open;
	}



	public double getHigh() {
		return high;
	}



	public void setHigh(double high) {
		this.high = high;
	}



	public double getLow() {
		return low;
	}



	public void setLow(double low) {
		this.low = low;
	}



	public double getClose() {
		return close;
	}



	public void setClose(double close) {
		this.close = close;
	}



	public int getVolumn() {
		return volumn;
	}



	public void setVolumn(int volumn) {
		this.volumn = volumn;
	}

}
